home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / wemdemo4.zip / INFO / CL (.txt) < prev    next >
GNU Info File  |  1994-09-21  |  32KB  |  684 lines

  1. This is Info file ../info/cl, produced by Makeinfo-1.56 from the input
  2. file cl.txi.
  3.    Copyright (C) 1987 Cesar Quiroz
  4. File: cl,  Node: Top,  Next: Generalities,  Up: (DIR)
  5. Common Lisp Extensions
  6. **********************
  7.    The routines described in this chapter provide some of the
  8. functionality of Common Lisp inside Emacs Lisp.
  9. * Menu:
  10. * gen: Generalities.           Things you need to know.
  11. * sym: Symbols.                Gensym, gentemp, keyword-p, ...
  12. * lis: Lists.                  List*, pairlis, acons, ...
  13. * seq: Sequences.              Every, any, notevery, notany, ...
  14. * con: Conditionals.           When, unless, case, ecase.
  15. * ite: Iterations.             Do, do*, dolist, dotimes, ...
  16. * mul: Multiple Values.        Values, values-list, ...
  17. * ari: Integer Arithmetic.     Floor, ceiling, round, truncate, ...
  18. * stf: Generalized Variables.  Setf and friends.
  19. * str: Structures.             Like Pascal records or C structs.
  20. * mis: Miscellanea.            Odds and ends that didn't fit elsewhere.
  21. * tod: To Do.                  Suggestions for future hackery.
  22. File: cl,  Node: Generalities,  Next: Symbols,  Prev: Top,  Up: Top
  23. Generalities
  24. ============
  25.    This section tells you want you need to know about the routines in
  26. the file `cl.el', so that you can use them.  The distribution also
  27. includes this documentation and perhaps a few example files.
  28. License, Availability, Maintenance
  29. ----------------------------------
  30.    These files are covered by the GNU Emacs General Public License (if
  31. you don't know its terms, try `C-h C-c') and the statement of no
  32. warranty (again, you can type `C-h C-w' if you don't know its terms)
  33. also applies to them.
  34.    I, Cesar Quiroz, the original author of the software described here,
  35. will appreciate hearing about bug reports (and fixes), suggestions and
  36. comments, applying both to the code and to this documentation.  I don't
  37. promise to act on those communications, but whenever they might conduce
  38. to improvements of this software, I will make those improvements
  39. available to the general community through the Free Software
  40. Foundation.  You can reach me at the following net addresses:
  41.      quiroz@seneca.cs.rochester.edu quiroz@rochester.arpa {allegra |
  42.      seismo | ... } ! rochester ! quiroz CSNET: Cesar Quiroz at node
  43.      Rochester
  44. Purpose and Limitations
  45. -----------------------
  46.    These routines were written with two purposes in mind:
  47.   1. To make programming in Emacs Lisp even more compatible with Common
  48.      Lisp.  Indeed, my original motivation was to have a `do' macro.
  49.   2. To facilitate to novice Lisp programmers a chance to practice with
  50.      features commonly found only in expensive implementations of Lisp.
  51.    In order to satisfy these purposes, the routines were written in
  52. such a way that it is practical to use them inside Emacs: no effort was
  53. given to implement features that could slow down the host Emacs
  54. unnecessarily nor require recoding of the Emacs Lisp interpreter.
  55.    For instance, no support is given to floating point arithmetic.
  56.    So, I have tried to implement a subset of the functionality of
  57. Common Lisp.  Whatever is implemented, has syntactic and semantic
  58. properties like the equally named features of Common Lisp, but not all
  59. the relevant features have been implemented (*note To Do::., for some
  60. suggestions).  When deciding what to include, I have tried to strike a
  61. balance between these constraints:
  62.   1. Keep it simple, I didn't want to spend much time in this idea.
  63.   2. Keep it compatible with Common Lisp.
  64.   3. Keep it flexible, so my code doesn't oppose a better
  65.      implementation (when this looked hard, I just didn't implement the
  66.      feature).
  67.   4. Keep an eye on the intended use of Emacs Lisp: to support an
  68.      advanced editor.  I don't expect that more arithmetic support will
  69.      be as conducive to this goal as having better iterations and
  70.      conditionals will.
  71.    For background, the reference is "Common Lisp: The Language" by Guy
  72. Steele Jr. (Digital Press, 1984).  For all the features described here
  73. you can assume that the intent has been to provide the syntax and
  74. semantics of the features of like name in the book.  For the most part,
  75. this documentation will concentrate on how my routines fail to
  76. implement Common Lisp faithfully.
  77. Specific Limitations
  78. ....................
  79.    Emacs Lisp and Common Lisp differ enough to make some of the
  80. emulation difficult, expensive or nearly impractical.  Some specific
  81. limitations are stated here:
  82.   1. Common Lisp is lexically scoped (mostly), while Emacs Lisp is
  83.      dynamically scoped.  Things like `block', `return', `tagbody' are
  84.      then practically impossible to imitate correctly (in principle,
  85.      rewriting `eval', `apply' and a couple of other functions would
  86.      suffice, problem is that such rewriting amounts to  a new
  87.      interpreter on top of the old.)  Things like `implicit-blocks',
  88.      `implicit-tagbodies' and the like have not been implemented at all.
  89.      Where they are needed, the most you can assume is that I tried to
  90.      put `implicit-progns' around places where it made sense.
  91.   2. Emacs Lisp's `lambda' does not support all the possible argument
  92.      markers.  Similarly, `defmacro' doesn't support automatic
  93.      destructuring of the calls.  An approximation to a keyword-based
  94.      calling style was implemented, mainly for the sake of `defstruct',
  95.      but is not general enough.
  96.   3. Emacs Lisp supports arithmetic only on integers.
  97.   4. Emacs Lisp doesn't support many of the basic types of Common Lisp.
  98.      In particular, there are no arrays beyond vectors and strings
  99.      (although these ones are compatible), characters are essentially
  100.      small integers, etc.
  101.   5. There are no declarations in Emacs Lisp (in the sense of Common
  102.      Lisp's `declare', `proclaim', ...) nor there is a explicit lattice
  103.      of types.  These limitations could be effectively overcome from
  104.      Lisp code (to a extent), but I don't see them as a very pressing
  105.      need, if a need at all in Emacs Lisp.  `defstruct' can be used to
  106.      generate new types that can be recognized at runtime.
  107.   6. The Emacs Lisp reader is not programmable.  The syntax it accepts
  108.      is almost standard, but it preempts '?' as a dispatching macro of
  109.      sorts.  The `format' function is incompatible with Common Lisp.
  110.      There isn't a `quasi-constant' notation (the usual `backquote' of
  111.      Common Lisp).  None of these differences causes any problems when
  112.      writing Emacs Lisp (although the lack of backquoting is felt
  113.      sorely), but they oppose a Common Lisp emulation.
  114. Loading and Compiling
  115. ---------------------
  116.    The file `cl.el' provides the `cl' feature, you can use this to test
  117. whether these routines have been loaded, or to load them from your code
  118. (by means of `(require 'cl)').  The compiled file is a little larger
  119. than 50K bytes.
  120.    If you need to recompile the sources, make sure you load them first
  121. on the Emacs that will do the recompilation.  This is because many
  122. syntactic characteristics (like the special forms) have been
  123. implemented as macros and you need to make sure that macros are known
  124. to the compiler before they are used.
  125.    These extensions work correctly when interpreted in a GNU Emacs of
  126. version 17.64 or beyond.  Compiling them requires a more recent byte
  127. compiler, preferably one strictly younger than version 18.XX.
  128. On Line Help
  129. ------------
  130.    The routines in this file have documentation strings, so you can (and
  131. should) consult them for the exact syntax allowed.  That information is
  132. not repeated in this manual.  Some of the routines are also documented
  133. explicitly in the Common Lisp reference, their doc-strings begin with
  134. `[cl]' to represent this fact.
  135.    The rest (those without the `[cl]' mark) are auxiliary functions or
  136. macros used by the rest of the implementation.  They are not constrained
  137. by any standard and are advertised only in as much as they can be useful
  138. in other applications.
  139.    Each of the following sections contains a subsection called `Features
  140. Provided'.  It lists briefly the user-visible features of this
  141. implementation.  In its entries, names by themselves refer to functions.
  142. Macros and variables are identified by a `MACRO' or a `VARIABLE' ahead
  143. of their names.
  144. File: cl,  Node: Symbols,  Next: Lists,  Prev: Generalities,  Up: Top
  145. Symbols
  146. =======
  147.    The most important omission is that of a PACKAGES mechanism.  (For a
  148. possible implementation, *note To Do::.)  Whenever a Common Lisp
  149. function expects a package, I have substituted an obarray.  There is a
  150. hack to have pseudo-keywords, see below.
  151.    There are two other notorious omissions over which I haven't lost any
  152. sleep.  The first is the lack of a `remprop' function, which could be
  153. easily provided if needed.  The second is the lack of ways to modify the
  154. print name of a symbol.  This one would probably be good only to
  155. introduce strange bugs, so I don't miss it.
  156. Features Provided
  157. -----------------
  158. `VARIABLE *gensym-index*'
  159. `VARIABLE *gensym-prefix*'
  160. `VARIABLE *gentemp-index*'
  161. `VARIABLE *gentemp-prefix*'
  162.      These variables are used to keep the state of the generator of new
  163.      names.  Better leave them alone.
  164. `gensym'
  165. `gentemp'
  166.      These do the same as the Common Lisp names of like names.
  167. `MACRO defkeyword'
  168. `keyword-of'
  169. `keywordp'
  170.      These provide the pseudo-keywords implementation.
  171. Keywords
  172. --------
  173.    The lack of packages makes it difficult to implement keywords
  174. correctly.  I have provided a macro `defkeyword' that takes a symbol
  175. and makes sure it evaluates to itself.  (So, it is like `defconst'.)
  176. If your programs ever need keywords, put a bunch of calls to
  177. `defkeyword' at the beginning of your code, so when loaded they will be
  178. in effect.
  179.    The (standard) predicate `keywordp' tests to see if the given
  180. symbol's name begins with a colon and then ensures that it evaluates to
  181. itself.
  182.    The function `keyword-of' takes a symbol and returns a keyword of
  183. like name.
  184.       (keyword-of 'foo)
  185.      :foo
  186.       (keyword-of ':bar)
  187.      :bar
  188.    This feature was added mainly to support `defstruct' and the tests of
  189. the sequence functions.  It is fragile and easy to fool.
  190. New Symbols
  191. -----------
  192.    A common need (especially when writing macros) is to be able to
  193. invent new names for things.  I provide the `gensym' and `gentemp'
  194. functions.  The global state needed is kept in the variables
  195. `*gentemp-index*', `*gentemp-prefix*', `*gensym-index*' and
  196. `*gensym-prefix*'.  Changing them, especially the index ones, is a very
  197. bad idea.  I am not providing the Common Lisp default prefixes ('G' for
  198. `gensym' and 'T' for `gentemp') because of debugging paranoia.  My
  199. default prefixes are harder to come by when giving sane names to
  200. things.
  201. File: cl,  Node: Lists,  Next: Sequences,  Prev: Symbols,  Up: Top
  202. Lists
  203. =====
  204.    Lists (indeed, conses) are so deeply involved in Lisp that there
  205. seems to be little need to justify improving the list handling of a
  206. Lisp.
  207.    Common Lisp, however, is a rather huge Lisp.  I haven't provided all
  208. the functions in the chapter of lists, mainly because some of them
  209. could be implemented correctly only if keyword arguments were supported.
  210. That explains why I haven't rushed to provide `subst', `sublis', etc.
  211. Also, that explains the rather temporary nature of the implementation
  212. of `member' and `adjoin'.  I will welcome any efforts to extend this
  213. work.
  214. Features Provided
  215. -----------------
  216. `endp'
  217. `list*'
  218. `list-length'
  219.      Very standard utilities.  List* has proven especially useful to
  220.      overcome the lack of a real `backquote'.  In addition, things that
  221.      usually required the relatively clumsy
  222.           (cons 'a (cons 'b oldlist))
  223.           (append (list a b) oldlist)
  224.      can now be simply put:
  225.           (list* 'a 'b oldlist)
  226.      See also `acons'.
  227. `member'
  228.      Another well known function.  Supports test with `eql' only.
  229. `acons'
  230. `pairlis'
  231.      These two are part of the standards association lists
  232.      implementation.  I am leaving `sublis' as an exercise for the
  233.      reader.
  234. `adjoin'
  235.      Done mainly for the sake of `pushnew'.
  236. `butlast'
  237. `last'
  238. `ldiff'
  239.      Occasionally useful ways to access the last cons or a specified
  240.      tail of a list.  I don't remember why there isn't a `tailp' here.
  241. `c[ad][ad][ad][ad]r, up to four a's or d's'
  242.      These 28 functions (and their setf inverses) have been provided
  243.      once and for all.  Many packages contributed to Emacs Lisp contain
  244.      macros that implement some of these, I think this code will make
  245.      most of them unnecessary.
  246. `first'
  247. `rest'
  248. `second'
  249. `third'
  250. `fourth'
  251. `fifth'
  252. `sixth'
  253. `seventh'
  254. `eighth'
  255. `ninth'
  256. `tenth'
  257.      More standard accessors (and their setf inverses).  Not
  258.      particularly useful but easy to provide.
  259. `setnth'
  260. `setnthcdr'
  261.      These functions are non-standard.  They are here for `defsetf'
  262.      purposes only, but they might be useful on their own.
  263. File: cl,  Node: Sequences,  Next: Conditionals,  Prev: Lists,  Up: Top
  264. Sequences
  265. =========
  266.    Sequences are partly supported in Emacs Lisp (see, for instance, the
  267. `elt' function).  This limited support is compatible with Common Lisp,
  268. so it should be easy to extend.  However, the lack of keyword arguments
  269. makes many of the functions impossible so far (but, as mentioned below,
  270. a basic framework for that extension is provided here).
  271.    The functionality really provided here is given by the functions
  272. (essentially, predicates) `every', `some', `notevery', `notany'.  I
  273. have found them useful countless times, so I thought to provide them
  274. before anything else.
  275.    That still leaves many omissions, though.
  276. Features Provided
  277. -----------------
  278. `every'
  279. `notany'
  280. `notevery'
  281. `some'
  282.      Extremely useful functions.  If your favorite Lisp doesn't have
  283.      them, you are missing a lot.
  284. `setelt'
  285.      A setf-inverse to `elt'.
  286. `add-to-klist'
  287. `build-klist'
  288. `extract-from-klist'
  289.      A "klist" is just an alist whose keys are keywords.  I based the
  290.      pseudo-keyword argument support of `defstruct' on this idea, but
  291.      their best fit is here, as they could help to write the remaining
  292.      sequence-handling functions (`find', `substitute', ...) that I
  293.      didn't provide for the lack of a good keyword arguments mechanism.
  294. `elt-satisfies-if-not-p'
  295. `elt-satisfies-if-p'
  296. `elt-satisfies-test-p'
  297. `elts-match-under-klist-p'
  298.      The Common Lisp book defines some of the semantics of sequence
  299.      functions in terms of satisfaction of certain tests.  These
  300.      predicates provide that functionality, but I haven't integrated
  301.      them with the rest of the extensions.  However, I thought it was
  302.      better to include them anyway, as they can serve somebody else as
  303.      a starting point.
  304. File: cl,  Node: Conditionals,  Next: Iterations,  Prev: Sequences,  Up: Top
  305. Conditionals
  306. ============
  307.    An elementary incompatibility prevents us from producing true Common
  308. Lisp here.  The `if' forms are different.  In Emacs Lisp, `if' can take
  309. any number of subforms, there being a CONDITION form, a THEN form, and
  310. after them any number of ELSE subforms, which are executed in an
  311. implicit `progn'.  Moreover, that style is widely used in the Emacs
  312. sources, so I thought most impractical to break with it to support
  313. Common Lisp's `if' (where only one ELSE form is tolerated).  For the
  314. most part, I use `cond' almost always, so it doesn't bother me much.
  315. If you use single-branch `if's often, consider `when' or `unless' as
  316. alternatives.
  317.    `case' and `ecase' are a convenient way to write things that usually
  318. end up in a very baroque `cond'.
  319. Features Provided
  320. -----------------
  321. `MACRO case'
  322. `MACRO ecase'
  323. `MACRO unless'
  324. `MACRO when'
  325.      The standard stuff, completely implemented.
  326. File: cl,  Node: Iterations,  Next: Multiple Values,  Prev: Conditionals,  Up: Top
  327. Iterations
  328. ==========
  329.    Having a `do' macro was my original motivation.  The alternatives in
  330. standard Emacs Lisp are either expensive (recursion) or correspond
  331. directly to the expansion of my macros:
  332.       (macroexpand '
  333.        (do ((i 0) (j 1 (+ 1 j)))
  334.            ((> j (foo i)) (cons i bar))
  335.          (setq i (baz i j))))
  336.      
  337.      (let ((i 0) (j 1))
  338.        (while (not (> j (foo i)))
  339.          (setq i (baz i j))
  340.          (psetq j (+ 1 j)))
  341.        (cons i bar))
  342.    So I prefer to leave to the macros the problem of remembering the
  343. details right.
  344.    The incompatibilities are due to the problems already discussed
  345. (*note Generalities::., for more details).
  346.    If you write Emacs Lisp code often, you will find enough uses for
  347. these.  Examples are cooking up a translation table to move C-s out of
  348. the way of multiplexers, switches, concentrators and similar fauna, or
  349. building keymaps.
  350. Features Provided
  351. -----------------
  352. `MACRO do'
  353. `MACRO do*'
  354. `MACRO dolist'
  355. `MACRO dotimes'
  356.      The standard, but for the lack of implicit blocks.
  357. `MACRO loop'
  358.      The basic standard one, not the fancy one.  As per the book, warns
  359.      you about atomic entries at the surface of the macro (to guarantee
  360.      that the fancy `loop' macros can be made standard later).
  361. `MACRO do-all-symbols'
  362. `MACRO do-symbols'
  363.      These operate on obarrays, the default is the current one.
  364. File: cl,  Node: Multiple Values,  Next: Integer Arithmetic,  Prev: Iterations,  Up: Top
  365. Multiple Values
  366. ===============
  367.    The multiple values mechanism covers (simply and elegantly, in my
  368. opinion) various common needs:
  369.   1. The case where a function returns a composite value, that has to be
  370.      assembled in the callee and disassembled in the caller.  An
  371.      example is `pair-with-newsyms'.
  372.   2. The case where a function might cheaply compute redundant
  373.      information that is useful to the caller only eventually.  For
  374.      instance, routines that compute quotients and remainders together,
  375.      whose callers might be more often interested in just receiving the
  376.      quotient.
  377.   3. The case of functions that usually return a useful value, but
  378.      might need to elaborate on occasion (say, returning a reason code
  379.      too).
  380.    The general idea is that one such function always returns the extra
  381. values, but only callers that are aware of this ability receive them.
  382. Unaware callers just receive the first value.
  383.    I think my implementation is pretty much complete.  I am imposing no
  384. limits on the number of multiple values a function may return, so I am
  385. not providing the constant `multiple-values-limit'.  You can assume
  386. multiple values are bound by the memory size only.
  387. Features Provided
  388. -----------------
  389. `values'
  390. `values-list'
  391.      These are the forms that produce multiple values.
  392. `MACRO multiple-value-bind'
  393. `MACRO multiple-value-call'
  394. `MACRO multiple-value-list'
  395. `MACRO multiple-value-prog1'
  396. `MACRO multiple-value-setq'
  397.      These are the forms that receive multiple values.
  398. `VARIABLE *mvalues-count*'
  399. `VARIABLE *mvalues-values*'
  400.      Used by the implementation.  Don't touch them!
  401. File: cl,  Node: Integer Arithmetic,  Next: Generalized Variables,  Prev: Multiple Values,  Up: Top
  402. Integer Arithmetic
  403. ==================
  404.    I have provided most of the functions that are supposed to act on
  405. integers.  Of those that take arbitrary numbers, I have implemented
  406. those that have a reasonable implementation if restricted to integers
  407. only, although some more could be added (like a restricted form of
  408. `expt').
  409.    Being a little worried about the bad fame that affects some
  410. implementations of the '%' C operator, I have taken perhaps unnecessary
  411. precautions whenever integer division is concerned (see the function
  412. `safe-idiv').  This should be of interest only when dividing numbers
  413. that might be negative, but I have preferred here to be safe rather
  414. than fast.
  415. Features Provided
  416. -----------------
  417. `abs'
  418. `signum'
  419.      The usual.
  420. `gcd'
  421. `lcm'
  422.      The usual.
  423. `isqrt'
  424.      A rather annoying function.  Only use I can think of: to cut short
  425.      a prime number sieve.
  426. `evenp'
  427. `oddp'
  428. `plusp'
  429. `minusp'
  430.      A few predicates that use to come handy.
  431. `ceiling'
  432. `floor'
  433. `round'
  434. `truncate'
  435. `mod'
  436. `rem'
  437.      The intention is to give everybody his preferred way to divide
  438.      integers.  I have tried not to depend on the unreliable semantics
  439.      of C's integer division, I hope I got it right.  Read the code
  440.      when in doubt.
  441. File: cl,  Node: Generalized Variables,  Next: Structures,  Prev: Integer Arithmetic,  Up: Top
  442. Generalized Variables
  443. =====================
  444.    This implementation has many limitations.  Take a look to see if you
  445. want to overcome them, the fixes might prove unnecessarily expensive for
  446. Emacs purposes.  The ones I am clearly aware of:
  447.   1. Common Lisp suggests an underlying mechanism (the setf-methods) to
  448.      implement generalized variables.  I have used ad-hoc ideas that
  449.      gave me a rather trivial implementation that suffers from some
  450.      inflexibility.  As a result, `defsetf' only admits the simplest
  451.      form and there is no `define-modify-macro' nor there are functions
  452.      to handle the (nonexistent) setf-methods.
  453.   2. I haven't implemented (I was uninterested) `getf' and friends.
  454.      This shouldn't be hard.
  455.    In addition to providing this mechanism, I have written `defsetf's
  456. for almost every accessor I thought of.  There is room for improvement
  457. here, as Emacs Lisp provides many types of its own (buffers, windows,
  458. keymaps, syntax tables, ...) for which pairs of accessors and mutators
  459. could be defined.
  460.    If you want to check whether a function has a setf-inversor, look at
  461. the property `:setf-update-fn' of its name.  This is a characteristic
  462. of my implementation, not mandated by Common Lisp, so you shouldn't use
  463. it in code, but only to determine interactively what can be setf'd.
  464. Features Provided
  465. -----------------
  466. `MACRO setf'
  467. `MACRO psetf'
  468.      Almost complete implementation.  `Setf' should handle `apply'
  469.      inside itself and not in a `defsetf', but the difference is so
  470.      minute I feel lazy about fixing this. `Psetf' is the version where
  471.      the assignments occur in parallel.
  472. `MACRO defsetf'
  473.      Very sketchy implementation.  I will appreciate if somebody puts
  474.      some time in implementing the whole works of setf-methods and such.
  475. `MACRO incf'
  476. `MACRO decf'
  477.      The usual and standard.
  478. `MACRO pop'
  479. `MACRO push'
  480. `MACRO pushnew'
  481.      Should be the usual, but I haven't had the time to test them
  482.      properly.
  483. `MACRO rotatef'
  484. `MACRO shiftf'
  485.      Very fancy.  Good for implementing history rings and such.  To
  486.      swap two values, the following forms are equivalent:
  487.           (rotatef a b)
  488.           (psetf a b b a)
  489.           (psetq a b b a)  ;not good for anything but variables
  490. File: cl,  Node: Structures,  Next: Miscellanea,  Prev: Generalized Variables,  Up: Top
  491. Structures
  492. ==========
  493.    I haven't had the time to construct a complete implementation of
  494. structures, but the part provided should stand on its own for many
  495. purposes.  I am not supporting `BOA constructors', nor typed slots (the
  496. `:type', `:named' and `:initial-offset' options), nor explicit
  497. representational types.  The rest should be pretty much complete.  See
  498. the example file `fractions.el' for an idea of how complete the
  499. implementation is, and for exercises.
  500.    When writing these functions, I noticed I was incurring in lots of
  501. auxiliaries.  I used dollar signs in their names, in the hope that this
  502. could prevent clashes with user functions.  In retrospect, I should have
  503. done it in the other sections, too.
  504. Features Provided
  505. -----------------
  506. `MACRO defstruct'
  507.      Create records (a la C structs) and use them as types in your
  508.      programs.  Almost completely standard.
  509. `make$structure$instance'
  510.      This non-standard function implements most of the `guts' of the
  511.      `make-' constructors.  It can be used as an example of the pseudo
  512.      keyword-arguments.
  513. File: cl,  Node: Miscellanea,  Next: To Do,  Prev: Structures,  Up: Top
  514. Miscellanea
  515. ===========
  516. Features Provided
  517. -----------------
  518. `MACRO psetq'
  519.      A parallel-assignments version of `setq', makes the expansions of
  520.      `do' and `do*' be very similar, as they should.  Otherwise used to
  521.      swap two values, now superseded by `rotatef'.
  522. `duplicate-symbols-p'
  523. `pair-with-newsyms'
  524. `reassemble-argslists'
  525. `unzip-list'
  526. `zip-lists'
  527.      These are utilities I find useful when parsing a call or
  528.      generating code inside a macro.  Non standard.
  529. File: cl,  Node: To Do,  Prev: Miscellanea,  Up: Top
  530. To Do
  531. =====
  532.    No doubt many people will like to extend the functionality of these
  533. routines.  When considering doing so, please try and do it in such a way
  534. that your implementation of a subset of the functionality of Common Lisp
  535. is not inimical with a more extensive or more correct one.  For
  536. definiteness, ask yourself the questions:
  537.    * Will my code run under a correct implementation of Common Lisp?
  538.    * Will a correct implementation of Common Lisp run if my code is
  539.      loaded?
  540. The first question tests the pertinence of your extensions.  The second
  541. tries to discover "extensions" that prevent correct implementations of
  542. other features.  Please tell me if you notice a case in which my code
  543. fails to pass any of those tests.
  544.    The next subsections propose some more extensions.  I hope that they
  545. are attempted by people learning Lisp, as a way to enhance their
  546. understanding.  Of course, experts are also admitted.
  547. Keyword Arguments
  548. -----------------
  549.    Some effort has been done to handle keywords almost right.  For
  550. instance, a structure constructor (*note Structures::.) can be invoked
  551. with keyword arguments.
  552.    Look for the functions whose names have a `klist' in them.  They
  553. were written to facilitate parsing calls with keyword arguments, but I
  554. haven't done a complete implementation yet.  (Note that `member',
  555. `assoc' and perhaps some other function, have to be implemented
  556. independently of the general framework.  More details by Email if you
  557. want to try your hand at this.)
  558. Mapping Functions
  559. -----------------
  560.    There is enough support to write `maplist', `mapl', etc.  Emacs Lisp
  561. already provides some of the mapping functions, the trick now is to
  562. code the rest in a very efficient manner, so there will be an incentive
  563. to use `maplist' over an explicit iteration.  I have a draft
  564. implementation, but I don't have the time to test it now.
  565. Complete the current implementation
  566. -----------------------------------
  567.    Some of the features described above are only a partial
  568. implementation of the Common Lisp features.  Things that cry for a more
  569. complete form:
  570. `defsetf'
  571.      Only the simplest format is supported.  The most general one is
  572.      needed too.  Also, try to get `define-setf-method' and
  573.      `get-setf-method' to work.
  574. `define-modify-macro'
  575.      Same as above.  The modify-macros provided are all ad hoc.
  576. `defstruct'
  577.      I think my version recognizes all the options and then proceeds to
  578.      ignore most of them.  Making sure that at least good error
  579.      messages are produced would be nice.  Also, what about BOA
  580.      constructors?
  581.    There are other places where your programming ingenuity would help us
  582. all.  For instance, `subst', `sublis' and the like could be easily
  583. provided in the LISTS section.  (I haven't done it because I wanted to
  584. have the keyword arguments stuff first.)
  585. Hash Tables
  586. -----------
  587.    A very simple implementation of hash tables would admit only strings
  588. as keys.  For each string and a given number of buckets (a prime is
  589. desirable here), add the numeric values of all (or of a reasonable
  590. subset) of the characters and assign the bucket whose index is the
  591. remainder of the sum modulo the (prime) number of buckets.
  592.    A more convenient implementation can then be based on using
  593. `prin1-to-string' on an arbitrary Lisp object and using the output
  594. string as a key. This should make it easy to write `sxhash'.  Remember
  595. that one needs to ensure that `(equal x y)' should imply that
  596. `(= (sxhash x) (sxhash y))'; and also that the keys are state-less (so
  597. you can write them to a file and read them back later).
  598.    Don't forget to provide a `defsetf' for `gethash'.
  599. Packages
  600. --------
  601.    Packages should be easy to implement on top of a good hash table
  602. implementation, either by using it directly or by reusing some shared
  603. code.  Don't worry too much about efficiency: package qualification has
  604. no run-time cost, only read- and print-time costs.
  605.    The difficult thing is to integrate it correctly.  You have to
  606. replace the built-in functions `read' and `write'.  This is not as bad
  607. as writing a programmable reader, but still a pain.  For starters, your
  608. routines could remember the default definitions of the above mentioned
  609. functions:
  610.      (setf def-reader  (symbol-function 'read))
  611.      (setf def-printer (symbol-function 'print))
  612.      ...
  613.    And then your specialized functions could just use `apply' to
  614. exercise the default ones, intercepting their activity in time to do the
  615. package qualification.  You might have to do this to `prin1',
  616. `prin1-to-string' and friends.
  617. Streams and Files
  618. -----------------
  619.    This is the first "To Do" that might require doing some C
  620. programming.  The purpose is to construct an efficient byte stream
  621. abstraction that will allow Streams and Files to be handled.  Think of
  622. stdio, not Unix I/O, because Emacs already runs under other operating
  623. systems.  Also, think of doing it in a way that can be generalized
  624. easily (for instance, streams kept in memory without a file behind,
  625. streams as an interface to a windowing system, etc.)  Of course, the
  626. intended syntax is that of Common Lisp.
  627. Reader and Printer
  628. ------------------
  629.    The Emacs Lisp reader (the C function `Fread') is not reentrant nor
  630. programmable.  It could be fixed as Lisp Code, but that is probably
  631. uglily expensive (as bad as redoing `eval' and `apply' to support
  632. lexical scoping).  Doing this  extension is probably a bad idea: a
  633. Common Lisp reader is incompatible with Emacs Lisp code (because of the
  634. `?\' constructions) and the most important rule to keep in mind is that
  635. this code is running under Emacs, so the host shouldn't be burdened too
  636. much with these emulations.  Same goes for a more complete printer (a
  637. Common Lisp `format' would be incompatible with the Emacs Lisp one).
  638. Backquote
  639. ---------
  640.    Even if the reader is not made programmable nor reentrant, a
  641. backquoting mechanism could come handy.  You need to study the way the
  642. current reader does `quote' and hack from there.  This might be a more
  643. worthwhile extension than the complete rewrite of the reader.
  644. Wild Ideas
  645. ----------
  646.    Perhaps there is a way to implement `block', `tagbody', `return' and
  647. friends in spite of the dynamic scoping of Emacs Lisp.  By this, I mean
  648. an adequate definition that preserves remotely the original intent and
  649. still provides a sensible set of constructs.  Other dynamically scoped
  650. Lisps have these features, so implementing them is not necessarily
  651. impossible.
  652.    In the same spirit of these extensions would be to provide a port of
  653. something like Flavors (was there a PD version from Maryland, for Franz
  654. perhaps?) and then rephrase the language of major and minor modes in an
  655. Object Oriented paradigm.
  656.    Also, the rather gross `loop' macros that are out there in many Lisp
  657. systems could be helpful to some people (but then think of a
  658. `lisp-indent-hook' that handles them properly).
  659. Tag Table:
  660. Node: Top
  661. Node: Generalities
  662. Node: Symbols
  663. Node: Lists
  664. 10723
  665. Node: Sequences
  666. 12878
  667. Node: Conditionals
  668. 14673
  669. Node: Iterations
  670. 15665
  671. Node: Multiple Values
  672. 17120
  673. Node: Integer Arithmetic
  674. 18835
  675. Node: Generalized Variables
  676. 20176
  677. Node: Structures
  678. 22517
  679. Node: Miscellanea
  680. 23685
  681. Node: To Do
  682. 24236
  683. End Tag Table
  684.